<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue 响应式核心原理 2</title>
</head>
<body>
    <div id="app">
        李四
    </div>
    <script>

        let data = {
            name: "李四",
            age: 18
        }

        let vm = new Proxy(data, {
            get(target, key) {
                console.log("get 触发了")
                return target[key]
            },
            set(target, key, newVal) {
                console.log("set 触发了")
                if (target[key] === newVal) return
                target[key] = newVal
                document.querySelector("#app").textContent = target[key]
            }
        })

        vm.name = "张三"
        console.log(vm.name)

    </script>
</body>
</html>